"""
登录页面测试
"""
import time

from selenium.webdriver.common.by import By

from Utils.Utils import ForumDriver


class Login:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://127.0.0.1:58080/sign-in.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)

    # 登录成功
    def LoginSucTest(self):
        self.driver.delete_all_cookies()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        # 输入正确的密码和账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("user")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        # time.sleep(2)
        # 点击登录
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # 获取快照
        ForumDriver.GetScreenShot()
        # 查找元素首页
        self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title")
        # 查找元素发帖子
        text = self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-header.d-print-none > div > div > "
                                                  "div.col-auto.ms-auto.d-print-none > div > "
                                                  "a.btn.btn-primary.d-none.d-sm-inline-block.article_post").text
        print(text)

    def LoginFailTest(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        # 输入错的密码正确账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("user")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 点击登录
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        ForumDriver.GetScreenShot()
        # 查找弹窗元素 text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right >
        # div").get_attribute("value")
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        # print(text)


# login = Login()
# login.LoginSucTest()
# login.LoginFailTest()
# login.driver.quit()
